package com.practices2.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;

import com.practices2.R;

public class LoadingDialog extends Dialog {

	private Context mContext;
	private LayoutParams params;
	private LayoutInflater inflater;
	private TextView mTextView;
	private ImageView mImageView;
	private AnimationDrawable mAnimationDrawable;

	public LoadingDialog(Context context) {
		// super(context,R.style.);
		super(context, R.style.Dialog);
		mContext = context;

		inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.loading_dialog, null);
		setContentView(view);

		mImageView = (ImageView) findViewById(R.id.iv_dialog_loading);
		mImageView.setBackgroundResource(R.anim.loading);
		mAnimationDrawable = (AnimationDrawable) mImageView.getBackground();
		mAnimationDrawable.start();

		mTextView = (TextView) findViewById(R.id.loading_text);
		
		// 设置widow属性
		params = getWindow().getAttributes();// 得到WindowManager.LayoutParams 实例
		params.alpha = 1.0f;
		params.gravity = Gravity.CENTER;
		params.dimAmount = 0.5f; // 去掉背景遮盖

		getWindow().setAttributes(params);
	}

	public void setLoadingText(String content) {
		mTextView.setText(content);
	}
}
